The sample table atom ( 'stbl' ) contains the information you need to find a sample number based on a time and to find the sample's location based on the sample number. Samples are organized into chunks , containing one or more samples. The sample table atom contains the information you need to find out which chunk holds a given sample, where that chunk begins, and where in that chunk to find your sample.
The sample table atom contains five or six child atoms: the sample descriptions atom ( 'stsd' ), the time-to-sample atom ( 'stts' ), the sample-to-chunk atom ( 'stsc' ), the sample sizes atom ( 'stsz' ), and the chunk offset table atom ( 'stco' ) are mandatory. The synch samples atom ( 'stss' ) is optional. A diagram is shown below.
Before we dive into the structural details of the sample table child atoms, you might want to know how they're used. You'll need to examine the structure of the child atoms in detail to implement an actual algorithm.
Let's assume you know what the current movie time is and you want to find the appropriate hint sample to packetize some movie data. Here are the steps you take:
Begin by converting the movie time into timescale units for this hint track. Note: Time scale for the track is in the media handler header ( 'mdhd' ) atom.
Look in the time-to-sample atom ( 'stts' ) to determine which sample corresponds to the target time. The time-to-sample atom contains a table of samples and durations. You need to do some integer arithmetic to calculate the sample number from the time.
Once you have the sample number, use the sample-to-chunk atom to find out what chunk it's in. The sample-to-chunk atom contains a table listing chunks and samples-per-chunk. You need to do some integer arithmetic to calculate the chunk number from the sample number. You also need to do some modulo arithmetic to calculate which sample within that chunk is the one you want.
Find out where the chunk starts by looking in the chunk offset table atom ( 'stco' ). It's a simple table with the byte offset of each chunk. Note: The byte offset is into the file or resource specified by the data reference atom ( 'dref' ) inside the data information atom ( 'dinf' ).
Use the sample sizes atom ( 'stsz' ) to determine the byte offset within the chunk for your sample. The sample sizes atom contains either a number (the sample size, if all samples are of equal size) or a table with the size of each sample. You need to sum the size of every sample in your chunk prior to your target sample to obtain the byte offset of your sample within the chunk.
Add the byte offset of your sample to the byte offset of the chunk. That's where your hint track sample begins.
Now let's look at the sample table child atoms individually. Refer to the QuickTime File Format documentation for the structural details of each atom type.
The sample description atom ( 'stsd' ) contains information about the hint track samples. It specifies the data format (currently only RTP data format is defined) and which data reference to use (if more than one is defined) to locate the hint track sample data. It also contains some general information about this hint track, such as the hint track version number, the maximum packet size allowed by this hint track, and the RTP timescale. It may contain additional information, such as the random offsets to add to the RTP time stamp and sequence number.
The sample description atom can contain a table of sample descriptions to accomodate media that are encoded in multiple formats, but a hint track can be expected to have a single sample description at this time.
The sample description for hint tracks is defined below.
Table 1 Hint track sample description
Size | 4 |
Data format | 4 |
Reserved | 6 |
Data reference index | 2 |
Hint track version | 2 |
Last compatible hint track version | 2 |
Max packet size | 4 |
Additional data table | variable |
Entry length |
32-bit integer |
4 |
Data tag |
4-char code |
4 |
Data |
variable |
Entry length - 8 |
The time-to-sample atom ( 'stsd' ) for hint tracks is used normally, as described in the QuickTime File Format documentation (Movie Atoms section, Sample Atoms subsection). It contains a table you can use to determine which hint track sample corresponds to what time in the movie.
The synch samples atom ( 'stss' ) for hint tracks is used normally, as described in the QuickTime File Format documentation (Movie Atoms section, Sample Atoms subsection). It contains a table listing the samples that can be used for random access into the movie (key frame samples). This atom is optional. If it is not present, all sample frames can be used as key frames for this track.
The sample-to-chunk atom ( 'stsc' ) for hint tracks is used normally, as described in the QuickTime File Format documentation (Movie Atoms section, Sample Atoms subsection). It contains a table you can use to determine which chunk contains a particular sample.
The sample sizes atom ( 'stsz' ) for hint tracks is used normally, as described in the QuickTime File Format documentation (Movie Atoms section, Sample Atoms subsection). If all the samples are the same size, it holds the size in bytes as a 32-bit integer. Otherwise, it contains a table you can use to determine the size of any sample. You need to use this data to determine the byte offset of a given sample within a chunk.
The chunk offset table atom ( 'stco' ) for hint tracks is used normally, as described in the QuickTime File Format documentation (Movie Atoms section, Sample Atoms subsection). It contains a table with the byte offset of each chunk. The offset is into a file or resource specified indirectly by the data reference index field of the hint track sample description atom ( 'stsd' ). The actual data reference is in the data reference atom ( 'dref' ) inside the hint track's data information atom ( 'dinf' ).
| Previous | Chapter Contents | Chapter Top | Next |